﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FantastPlatform.Framework.Core;
using FantastPlatform.Framework.IModel;
using Newtonsoft.Json;
using FantastPlatform.Framework.Common.Serializable;
using FantastPlatform.Framework.Common;
using FantastPlatform.Framework.Exception;

namespace FantastPlatform.Framework.Model
{
    /// <summary>
    /// 职员
    /// </summary>
    public class Employee:Person,IEmployee
    {

        #region IEmployee 成员

        public virtual DateTime? EntryDate { get; set; }

        public virtual bool IsInService { get; set; }

        public virtual DateTime? QuitDate { get; set; }

        private IList<IUser> users;
        private IList<IUser> Users
        {
            get
            {
                if (CollectionHelper.IsNullOrEmpty<IUser>(users))
                    users = new List<IUser>();
                return users;
            }
            set
            {
                users = value;
            }
        }
        //[JsonConverter(typeof(InterfaceConverter<User>))]
        [JsonIgnore]
        public virtual IUser User
        {
            get
            {
                Check.Require<InvalidLengthException>(Users.Count <= 1, string.Format("员工：{0}不能对应多个用户！", this.Name));
                return CollectionHelper.IsNullOrEmpty<IUser>(Users) ? null : Users.SingleOrDefault();
            }
            set
            {
                Users.Clear();
                Users.Add(value);
            }
        }
        public virtual IList<IEmployeeContact> Contacts { get; set; }

        //[JsonConverter(typeof(InterfaceConverter<JobTitle>))]
        [JsonIgnore]
        public virtual IJobTitle JobTitle { get; set; }

        [JsonIgnore]
        public virtual IList<IEmployeePost> EmployeePosts { get; set; }
        #endregion

        #region IEmployee 成员

        [JsonIgnore]
        public virtual IList<IEmployeeCheckPerformance> EmployeeCheckPerformances
        {
            get;
            set;
        }
        [JsonIgnore]
        public virtual IList<IEmployeeCheckQuarter> EmployeeCheckQuarters
        {
            get;
            set;
        }
        [JsonIgnore]
        public virtual IList<IEmployeeCheckResult> EmployeeCheckResults
        {
            get;
            set;
        }
        [JsonIgnore]
        public virtual IList<IEmployeeCheckYear> EmployeeCheckYears
        {
            get;
            set;
        }
        [JsonIgnore]
        public virtual IList<IEmployeeEducation> EmployeeEducations
        {
            get;
            set;
        }
        [JsonIgnore]
        public virtual IList<IEmployeeJobExperience> EmployeeJobExperiences
        {
            get;
            set;
        }
        [JsonIgnore]
        public virtual IList<IEmployeePrizePunish> EmployeePrizePunishs
        {
            get;
            set;
        }

        #endregion
    }
}
